const date = new Date();
const today = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();

function scrollDown(entriesMax) {
    var data = [];
    const timer = setInterval(function () {
        window.scrollBy(0, 300)
        let newsDown = document.querySelectorAll(".feed-card-wrapper .title");
        if (newsDown.length > entriesMax) {
            clearInterval(timer)
            for (let i = 0; i < entriesMax; i++) {
                let tempText = newsDown[i].innerText;
                if (tempText != null && tempText.length > 1) {
                    data.push(tempText)
                }
            }
            chrome.storage.local.set({entry: data, toutiaoDate: today, progress: '2'}, () => {
                console.log("数据已存储");
                window.location.href = "https://cn.bing.com/search?q=" + today;
            });
        }
    }, 10);
}

const blackList = ["2", "3", "4"]

chrome.storage.local.get(['manualSearch', 'toutiaoDate', 'isAutoSignIn', 'entriesMax', 'progress'], function (results) {
    if (((results.isAutoSignIn === "1" && results.toutiaoDate !== today) || results.manualSearch === "1") && !blackList.includes(results.progress)) {
        scrollDown(results.entriesMax ?? 35)
    } else {
        console.log("今日已签到")
    }
})

